package waal.pc.frontend.config;

import javax.swing.DefaultListModel;

import waal.pc.backend.channels.Channel;
import waal.pc.backend.channels.ChannelEvent;
import waal.pc.backend.channels.ChannelEventListener;
import waal.pc.backend.module.Module;

public class ChannelList extends DefaultListModel<Channel> implements ChannelEventListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8226894142803313826L;
	private ChannelArea channelArea;
	private int lastIndex;
	
	public ChannelList(Module module, ChannelArea channelArea) {
		module.addChannelEventListener(this);
	}

	@Override
	public void actionChannelEvent(ChannelEvent e) {
		switch(e.getEvent()) {
		case 1: // Channel added
			this.addElement(e.getChannel());
			break;
		case 2: // Channel remove
			this.removeElement(e.getChannel());
			break;
		case 3: //Channel change active state
			this.channelArea.updateButton(e.getChannel());
			break;
		}
	}

	public int getLastIndex() {
		return lastIndex;
	}

	public void setLastIndex(int lastIndex) {
		this.lastIndex = lastIndex;
	}
}
